import {action, Service} from "adajs";
import User from "./../../lib/user";

class LoginService extends Service {
    defaultData() {
        let info = {
            checked: User.isAutoLogin(),
            toURL: "",
            loginURL: "",
            code: ""
        };
        if (User.isAdmin()) {
            info.code = "/api/Kaptcha/getCode";
        } else {
            info.code = "/api/lgb/Kaptcha/getCode";
        }
        return info;
    }

    @action("checked")
    check(current) {
        current.checked = !current.checked;
    }

    onupdate(current, data) {
        Object.assign(current, data);
    }

    @action("refreshCode")
    refreshCode(current) {
        current.code = current.code.split("?")[0] + "?t=" + new Date().getTime()
    }
}

export default LoginService;